package com.ygo.feihua;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ListView;
import cn.bmob.v3.BmobQuery;
import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.FindListener;
import com.ygo.feihua.Adaptergg;
import com.ygo.feihua.BmobTable.GongGao;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import android.support.v4.util.*;
import com.ygo.feihua.util.*;

public class ShezhiGggl extends Activity implements OnClickListener
{

	Button gl_addgg;
	ListView gl_lb;
	Gongju gj;
	DialogUtils du;
	Adaptergg adp;
	List<Map<String,Object>> data=new ArrayList<Map<String,Object>>();
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		// TODO: Implement this method
		super.onCreate(savedInstanceState);
		setContentView(R.layout.shezhi_gggl);
		csh();
		
	}
	private void csh(){
		gl_addgg=(Button) findViewById(R.id.gl_addgg);
		gl_lb=(ListView) findViewById(R.id.gl_gglb);

		gj=Gongju.getdx(this);
		du=DialogUtils.getdx(this);

		
		gl_addgg.setText("添加公告");
		gl_addgg.setOnClickListener(this);

		ggcsh();
	}

	@Override
	public void onClick(View p1)
	{
		switch(p1.getId()){
			case R.id.gl_addgg:
				startActivity(new Intent(this,GonggaoAdd.class));
				break;
		}
		// TODO: Implement this method
	}

	private void ggcsh() {
	du.dialogj1(false,"","加载中,请稍等");
		BmobQuery<GongGao> ggg=new BmobQuery<GongGao>();
		ggg.setLimit(50);
		ggg.order("-createdAt");
		ggg.findObjects(new FindListener<GongGao>(){

				@Override
				public void done(List<GongGao> p1, BmobException p2)
				{
					if(p2==null){
						for(GongGao g:p1){
							Map<String,Object> map=new ArrayMap<String,Object>();
							map.put("bt",g.getBiaoti());
							map.put("nr",g.getNeirong());
							map.put("id",g.getObjectId());
							data.add(map);

						}		
						if(data.size()==0){
							gj.show("无公告");
						}else{
							adp=new Adaptergg(ShezhiGggl.this,data);
							gl_lb.setAdapter(adp);
						}
					
					}else{
						gj.show("查询失败,原因为"+p2);
						
					}
					du.dis();
					// TODO: Implement this method
				}
			});
	}
}
